package controller;

import java.util.HashMap;
import java.util.Observer;

import model.Machine;
import model.QR;
import android.app.Activity;
import android.app.Application;

public class App extends Application 
{
	
	private HashMap<String, QR> scannedCodes = new HashMap<String, QR>();
	
	private Activity scanner;
	
	// dit moet een lijst worden (?)
	private String currentQR = "";
	
	private HashMap<String, Machine> machines = new HashMap<String, Machine>();
	
	public void setMachines(HashMap<String, Machine> machines)
	{
		this.machines = machines;
	}
	
	public Machine getMachine(String id)
	{
		return machines.get(id);
	}
	
	public Machine getCurrentMachine()
	{
		return machines.get(currentQR);
	}

	// string currentQR
	public String getCurrentQR() {
		if(!currentQR.isEmpty())
			return currentQR.substring(0,1);
		else return "";
	}

	public void setCurrentQR(String currentQR) {
		this.currentQR = currentQR;
	}	
	
	// scannedCode methods
	public void addScannedCode(String code, QR qr)
	{
		if(scanner != null)
		{
			qr.addObserver((Observer) scanner);
		}
		scannedCodes.put(code, qr);
	}
	
	public QR getScannedCode(String code)
	{
		return scannedCodes.get(code);
	}

	// main activity
	public Activity getScanner() {
		return scanner;
	}

	public void setScanner(Activity scanner) 
	{
		if(this.scanner == null)
		{
			this.scanner = scanner;
		}
	}
}
